﻿#pragma once

#include "common.h"
#include "mixer.h"

namespace anip
{
	namespace audio
	{
		class Waveform
		{
		private:
			int _sampleRate = 0;
			int _channels = 0;
			int _length = 0;
			short* _data = nullptr;

			class Instance : public SoundInstance
			{
			private:
				Waveform& _wav;

			public:
				Instance(Waveform& w) :
					_wav(w) {}

				int channelCount() const { return _wav._channels; }
				bool read(double* dest, unsigned int nSamples, unsigned int start);
			};

			Waveform() {}
		public:
			static Waveform* fromOGG(const string& filename);

			~Waveform()
			{
				delete[] _data;
			}

			int sampleRate() const { return _sampleRate; }
			int channelCount() const { return _channels; }

			SoundInstance* instantiate() { return new Instance(*this); }

			double getAmplitude(double time);

			const short* data() const { return _data; }

			double runningTime() const { return (double)_length / _sampleRate; }
		};
	}
}